package fightplan.business;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;

import com.jgoodies.binding.value.ValueHolder;
import com.jgoodies.binding.value.ValueModel;

public class TournamentHolder implements ValueModel {

	private ValueHolder tournament = new ValueHolder();
	private List<TournamentListener> listeners = new ArrayList<TournamentListener>();

	public TournamentHolder() {
		tournament.addValueChangeListener(new PropertyChangeListener() {
			public void propertyChange(PropertyChangeEvent evt) {
				fireChange();
			}
		});
	}

	public void addPropertyChangeListener(PropertyChangeListener listener) {
		tournament.addPropertyChangeListener(listener);
	}

	public void removeValueChangeListener(PropertyChangeListener listener) {
		tournament.removeValueChangeListener(listener);
	}

	public void addValueChangeListener(PropertyChangeListener listener) {
		tournament.addValueChangeListener(listener);
	}

	public Object getValue() {
		return tournament.getValue();
	}

	public void removePropertyChangeListener(PropertyChangeListener listener) {
		tournament.removePropertyChangeListener(listener);
	}

	public void setValue(Object newValue) {
		tournament.setValue(newValue);
	}

	// listeners

	public void addListener(TournamentListener listener) {
		listeners.add(listener);
	}

	public void removeListener(TournamentListener listener) {
		listeners.remove(listener);
	}

	public void fireChange() {
		for (TournamentListener listener : listeners) {
			listener.tournamentChanged();
		}
	}

}
